using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;using THSERP.BusinessEntities;using THSERP.BaseProvider;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using THSLib;using THSERP.BaseProvider;

namespace THSERP.Modules.Report
{
    public partial class RP009 : ReportForm
    {
        private THSList<ARCustomersInfo> lstCustomer;
        public RP009()
        {
            InitializeComponent();
            lstCustomer = new THSList<ARCustomersInfo>();
        }

        private void fld_btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void RP009_Load(object sender, EventArgs e)
        {
            fld_dgcARRP009Customers.Screen = this;
            fld_dgcARRP009Customers.InitializeControl();
            fld_lkeFK_ARPriceLevelID.Screen = this;
            fld_lkeFK_ARPriceLevelID.InitializeControl();

            fld_btnApply_Click(new object(), new EventArgs());
        }

        private void fld_btnApply_Click(object sender, EventArgs e)
        {
            StringBuilder queryBuilder = new StringBuilder();
            queryBuilder.Append(GenerateSearchQuery(THSUtil.GetTableNameFromBusinessObjectType(typeof(ARCustomersInfo))));
            lstCustomer.Clear();
            ARCustomersController objCustomersController = new ARCustomersController();
            DataSet ds = objCustomersController.GetDataSet(queryBuilder.ToString());
            foreach (DataRow row in ds.Tables[0].Rows)
            {
                ARCustomersInfo objCustomersInfo = (ARCustomersInfo)objCustomersController.GetObjectFromDataRow(row);
                objCustomersInfo.ARCustomerTotalPurchase = objCustomersController.GetTotalInvoiceAmount(objCustomersInfo.ARCustomerID);
                objCustomersInfo.ARCustomerTotalDiscount = objCustomersController.GetTotalInvoiceDiscount(objCustomersInfo.ARCustomerID);
                objCustomersInfo.ARCustomerTotalRefund = objCustomersController.GetTotalInvoiceRefund(objCustomersInfo.ARCustomerID);
                objCustomersInfo.ARCustomerTotalQty = objCustomersController.GetTotalQty(objCustomersInfo.ARCustomerID);
                lstCustomer.Add(objCustomersInfo);
            }
            fld_dgcARRP009Customers.DataSource = lstCustomer;
            fld_dgcARRP009Customers.RefreshDataSource();
        }
    }
}